import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-06-20
 * Time: 18:31
 */
class Solution12 {

    List<String> ret;
    StringBuilder path;
    public List<String> letterCasePermutation(String s) {
        ret = new ArrayList<>();
        path = new StringBuilder();

        dfs(s,0);

        return ret;
    }

    void dfs(String s, int pos) {
        if(pos == s.length()) {
            ret.add(path.toString());
            return;
        }

        //不改变
        char ch = s.charAt(pos);
        path.append(ch);
        dfs(s,pos+1);
        path.deleteCharAt(path.length()-1);//恢复现场

        //改变
        if(ch < '0' || ch > '9') {
            char tmp = change(ch);
            path.append(tmp);
            dfs(s,pos+1);
            path.deleteCharAt(path.length()-1);//恢复现场
        }
    }

    public char change(char ch) {
        if(ch >= 'a' && ch <= 'z') {
            return ch-=32;
        }
        return ch+=32;
    }
}
